package com.citrus.demo.api;

import com.citrus.demo.bean.CitrusDisease;
import com.citrus.demo.bean.Result;
import com.citrus.demo.services.CitrusDiseaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/api")
public class CitrusDiseaseController {

    @Autowired
    private CitrusDiseaseService citrusDiseaseService;

    @RequestMapping("/addcitrusdisease")
    @ResponseBody
    public Result addCitrusDisease(@RequestBody CitrusDisease citrusDisease){
        Result result = new Result();
        if (StringUtils.isEmpty(citrusDisease.getCitrusdisease_id())){
            result.setCode("201");
            return result;
        }
        result.setCode("200");
        return result;
    }

    @RequestMapping("/findcitrusdiseaseall")
    @ResponseBody
    public Result findCitrusDiseaseAll(){
        Result result = new Result();
        List<CitrusDisease> citrusDiseases = new ArrayList<>();
        citrusDiseases = citrusDiseaseService.findCitrusDiseaseAll();
        if (citrusDiseases == null){
            result.setCode("202");
            return result;
        }
        //System.out.println(citrusDiseases);
        result.setCode("203");
        result.setData(citrusDiseases);
        return result;
    }


}
